home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / commio0b.zip / FOSUNIT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-13  |  6KB  |  238 lines

  1. {$G+,A+}
  2. Unit FOSUnit;
  3. {
  4.           This unit is a companion to the COMMIO communications unit.
  5.                 Written by Jason Morriss a.k.a. Lief O'Pardy
  6.  
  7.                   Copyright (C) 1995,1996 by Jason Morriss
  8. }
  9. Interface
  10.  
  11. Function  F_Init(Comport: Byte) : boolean;
  12. Procedure F_Close(Comport: Byte);
  13. Procedure F_Parms(Comport: Byte; Baud: Word; DataBits: Byte; Parity: Char; StopBit: Byte);
  14. Procedure F_SendChar(Comport: Byte; C: Char);   {this DOES wait}
  15. Procedure F_Write(Comport: Byte; S: String);    {""}
  16. Procedure F_Writeln(Comport: Byte; S: String);  {""}
  17. Function  F_ReadChar(Comport: Byte) : Char;
  18. Procedure F_Dtr(Comport: Byte; State: Boolean);
  19. Procedure F_Flow(Comport: Byte; State: Boolean);
  20. Function  F_CD(Comport: Byte) : Boolean;
  21. Procedure F_Kill_Out(Comport: Byte);
  22. Procedure F_Kill_In(Comport: Byte);
  23. Procedure F_Flush(Comport: Byte);
  24. Function  F_Avail(Comport: Byte) : Boolean;
  25. Function  F_OkToSend(Comport: Byte) : Boolean;
  26. Function  F_Empty(Comport: Byte) : Boolean;
  27.  
  28.  
  29. Implementation
  30.  
  31. {───────────────────────────────────────────────────────────────────────────}
  32. Function F_Init(Comport: Byte):boolean; assembler;
  33. asm
  34.   mov  ah,4
  35.   mov  dl,[comport]
  36.   xor  dh,dh
  37.   dec  dl
  38.   xor  bx,bx
  39.   int  14h
  40.  
  41.   cmp  ax,1954h
  42.   jne  @@no
  43. @@yes:
  44.   mov  al,1
  45.   jmp  @@exit
  46. @@no:
  47.   xor  al,al
  48. @@exit:
  49. end;
  50. {───────────────────────────────────────────────────────────────────────────}
  51. Procedure F_Close(Comport: Byte); assembler;
  52. asm
  53.   mov  ah,5
  54.   mov  dl,[comport]
  55.   xor  dh,dh
  56.   dec  dl
  57.   int  14h
  58. end;
  59. {───────────────────────────────────────────────────────────────────────────}
  60. Procedure F_Parms(ComPort: Byte; Baud: word; DataBits: Byte; Parity: Char;
  61.                   StopBit: Byte);
  62. var c:byte;
  63. begin
  64.   if baud=0 then exit;
  65.   c:=0;
  66.  
  67.   c:=(databits-5);                           {000000xx}
  68.   c:=c or ((stopbit-1)shl 2);                {00000x00}
  69.  
  70.   Case upcase(Parity) of                     {000xx000}
  71. {   'N': c:=c or $00;}
  72.     'O': c:=c or $08;
  73.     'E': c:=c or $18;
  74.   end;
  75.  
  76.   Case Baud of                               {xxx00000}
  77.     19200: c:=c or $00;  {0000-0000}
  78.     38400: c:=c or $20;  {0010-0000}
  79.     300  : c:=c or $40;  {0100-0000}
  80.     600  : c:=c or $60;  {0110-0000}
  81.     1200 : c:=c or $80;  {1000-0000}
  82.     2400 : c:=c or $A0;  {1010-0000}
  83.     4800 : c:=c or $C0;  {1100-0000}
  84.     9600 : c:=c or $E0;  {1110-0000}
  85.     else if baud>38400 then c:=c or $20;
  86.   end;
  87.  
  88.   asm
  89.     xor  ah,ah;
  90.     mov  al,[c];
  91.     mov  dl,[comport]
  92.     xor  dh,dh
  93.     dec  dx;
  94.     int  14h;
  95.   end;
  96. end;
  97. {───────────────────────────────────────────────────────────────────────────}
  98. Procedure F_Dtr(Comport: Byte; State: Boolean); assembler;
  99. asm
  100.   mov  ah,6
  101.   mov  dl,[comport]
  102.   xor  dh,dh
  103.   dec  dl
  104.   mov  al,[state]
  105.   int  14h
  106. end;
  107. {───────────────────────────────────────────────────────────────────────────}
  108. Function F_CD(Comport: Byte) : Boolean; assembler;
  109. asm
  110.   mov  ah,3
  111.   mov  dl,[comport]
  112.   xor  dh,dh
  113.   dec  dl
  114.   int  14h
  115.  
  116.   mov  bl,al
  117.   xor  al,al
  118.   and  bl,80h
  119.   cmp  bl,80h
  120.   jne  @@exit
  121.   inc  al
  122. @@exit:
  123. end;
  124. {───────────────────────────────────────────────────────────────────────────}
  125. Procedure F_Flow(Comport: Byte; State: Boolean); assembler;
  126. asm
  127.   mov  ah,0Fh
  128.   mov  dl,[comport]
  129.   xor  dh,dh
  130.   dec  dl
  131.   xor  al,al
  132.   cmp  [state],0
  133.   je   @@off
  134.   mov  al,255
  135. @@off:
  136.   int  14h
  137. end;
  138. {───────────────────────────────────────────────────────────────────────────}
  139. Procedure F_Kill_Out(Comport: Byte); assembler;
  140. asm
  141.   mov  ah,9
  142.   mov  dl,[comport]
  143.   xor  dh,dh
  144.   dec  dl
  145.   int  14h
  146. end;
  147. {───────────────────────────────────────────────────────────────────────────}
  148. Procedure F_Kill_In(Comport: Byte); assembler;
  149. asm
  150.   mov  ah,10
  151.   mov  dl,[comport]
  152.   xor  dh,dh
  153.   dec  dl
  154.   int  14h
  155. end;
  156. {───────────────────────────────────────────────────────────────────────────}
  157. Procedure F_Flush(Comport: Byte); assembler;
  158. asm
  159.   mov  ah,8
  160.   mov  dl,[comport]
  161.   xor  dh,dh
  162.   dec  dl
  163.   int  14h
  164. end;
  165. {───────────────────────────────────────────────────────────────────────────}
  166. Function  F_Avail(Comport: Byte) : Boolean; assembler;
  167. asm
  168.   mov  ah,3
  169.   mov  dl,[comport]
  170.   xor  dh,dh
  171.   dec  dl
  172.   int  14h
  173.   and  ah,1
  174.   mov  al,ah
  175. end;
  176. {───────────────────────────────────────────────────────────────────────────}
  177. Function  F_OkToSend(Comport: Byte) : Boolean; assembler;
  178. asm
  179.   mov  ah,3
  180.   mov  dl,[comport]
  181.   xor  dh,dh
  182.   dec  dl
  183.   int  14h
  184.   and  ah,20h
  185.   shr  ah,5
  186.   mov  al,ah
  187. end;
  188. {───────────────────────────────────────────────────────────────────────────}
  189. Function  F_Empty(Comport: Byte) : Boolean; assembler;
  190. asm
  191.   mov  ah,3
  192.   mov  dl,[comport]
  193.   xor  dh,dh
  194.   dec  dl
  195.   int  14h
  196.   and  ah,40h
  197.   shr  ah,6
  198.   mov  al,ah
  199. end;
  200. {───────────────────────────────────────────────────────────────────────────}
  201. Procedure F_SendChar(Comport: Byte; C: Char); assembler;
  202. asm
  203.   mov  ah,1
  204.   mov  dl,[comport]
  205.   xor  dh,dh
  206.   dec  dl
  207.   mov  al,[c]
  208.   int  14h
  209. end;
  210. {───────────────────────────────────────────────────────────────────────────}
  211. Procedure F_Write(Comport: Byte; S: String);
  212. Var
  213.   i: Byte;
  214. begin
  215.   For i := 1 to Length(S) do F_SendChar(Comport,S[i]);
  216. end;
  217. {───────────────────────────────────────────────────────────────────────────}
  218. Procedure F_Writeln(Comport: Byte; S: String);
  219. begin
  220.   F_Write(comport,s);
  221.   F_SendChar(ComPort,#13);
  222.   F_SendChar(ComPort,#10);
  223. end;
  224. {───────────────────────────────────────────────────────────────────────────}
  225. Function F_ReadChar(Comport: Byte) : Char; assembler;
  226. asm
  227.   mov  ah,2
  228.   mov  dl,[comport]
  229.   xor  dh,dh
  230.   dec  dl
  231.   int  14h  {al=char}
  232. end;
  233. {───────────────────────────────────────────────────────────────────────────}
  234.  
  235.  
  236. end.
  237.  
  238.